package com.mate.cloud.message.exception;

import com.mate.cloud.common.constant.ResponseEnum;
import com.mate.cloud.common.exception.BusinessRuntimeException;
import org.apache.commons.lang.StringUtils;

import java.text.MessageFormat;

public abstract class IMMessageBusinessException extends BusinessRuntimeException {

    public IMMessageBusinessException() {
        super();
    }

    public IMMessageBusinessException(Integer code) {
        super();
        this.code = code;
    }

    /**
     * Create a new BeansException with the specified message.
     *
     * @param message
     */
    public IMMessageBusinessException(final String message) {
        super(message);
    }
    public IMMessageBusinessException(final Integer code, final String message) {
        super(code, message, StringUtils.EMPTY);
    }
    public IMMessageBusinessException(final Integer code, final String message, final String parameters) {
        super(code, message, parameters);
    }
    /**
     * 使用错误码枚举创建异常
     */
    public IMMessageBusinessException(final ResponseEnum errorMessage) {
        super(errorMessage.getCode(), errorMessage.getLocalMessage());
    }

    /**
     * 格式化错误消息
     */
    public IMMessageBusinessException formatMessage(Object... args) {
        if (this.errorMessage != null && args != null && args.length > 0) {
            this.errorMessage = MessageFormat.format(this.errorMessage, args);
        }
        return this;
    }

}
